<?php
defined('_XR_EXEC') or die();
/**
 * 逻辑处理类 
 */
class report_user_Model extends report_base_model
{

	/* 会员信息 */
	public function user1($formdata){
		$db = factory::getdbo();
		
		if(!isset($formdata['b_date']))    $formdata['b_date']  = ''; 
		if(!isset($formdata['e_date']))    $formdata['e_date']  = ''; 
		if(!isset($formdata['sex']))    	 $formdata['sex']  = ''; 
		if(!isset($formdata['state']))    	 $formdata['state']  = ''; 
		if(!isset($formdata['classes']))    	 $formdata['classes']  = ''; 
		if(!isset($formdata['sendweek1']))    	 $formdata['sendweek1']  = ''; 
		if(!isset($formdata['sendweek2']))    	 $formdata['sendweek2']  = ''; 
		
		$sql_where = 'select 
		a.* ,
		b.val as classes,
		c.val as identname,
		d.val as source,
		e.val as zone,
		f.name as deliver_val
		from t_user a 
		left join t_list_user_classes b on a.classes=b.id
		left join t_list_identname c on a.identname=c.id
		left join t_list_source d on a.source=d.id
		left join t_list_zone e on a.zone=e.id 
		left join t_deliver f on a.deliver_id=f.id
		where a.usertype=2 ';
		
		if($formdata['b_date']!=''){
			$sql_where .= ' and a.create_date >= "'.$formdata['b_date'].'"';	
		}
		if($formdata['e_date']!=''){
			$sql_where .= ' and a.create_date <= "'.$formdata['e_date'].'"';	
		}
		if($formdata['sex']!=''){
			$sql_where .= ' and a.sex = "'.$formdata['sex'].'"';	
		}
		if($formdata['classes']!=''){
			$sql_where .= ' and a.classes = "'.$formdata['classes'].'"';	
		}
		if($formdata['state']!=''){
			$sql_where .= ' and a.state = "'.$formdata['state'].'"';	
		}
		if($formdata['sendweek1']!=''){
			$sql_where .= ' and a.sendweek1 = "'.$formdata['sendweek1'].'"';	
		}
		if($formdata['sendweek2']!=''){
			$sql_where .= ' and a.sendweek2 = "'.$formdata['sendweek2'].'"';	
		}
		
		$rs = $db->loadassoclist($sql_where);
		 
		$s = '
		<table border="1">
			<thead>
				<tr>
					<th colspan="17" >基本信息</th>
					<th colspan="11" >收货信息</th>
					<th colspan="4" >备用收货信息</th>
					<th colspan="4" >合同信息</th>
				</tr>
				<tr>
					<th>序号</th>
					<th>配送类别</th>
					<th>配送方式</th>
					<th>会员类型</th>
					<th>会员编号</th>
					<th>姓名</th>
					<th>性别</th>
					<th >出生年月日</th>
					<th >证件类型</th>
					<th >证件号码</th>
					<th >籍贯</th>
					<th>饮食偏好</th>
					<th>手机号码</th>
					<th>联系地址</th>
					<th>固定电话</th>
					<th>电子邮箱</th>
					<th>业务代表</th>
					<th>客户来源</th>
					<th>备注</th>
					
					<th>配送频次1</th>
					<th>配送频次2</th>
					<th>省</th>
					<th>市</th>
					<th>区域</th>
					<th>小区名称</th>
					<th>配送地址</th>
					<th>配送联系人</th>
					<th>配送联系电话</th>
					<th>配送时间时段</th>
					<th>配送特殊需求</th>
					
					<th>备用配送地址</th>
					<th>备用配送联系人</th>
					<th>备用配送联系电话</th>
					<th>备用配送时间时段</th>
					
					<th>合同编号</th>
					<th>合同金额</th>
					<th>合同日期</th>
					<th>合同备注</th>
				</tr>
			</thead>
			<tbody>
		';
		   
		foreach($rs as $k=>$v){
			$s .= '
				<tr>
					<td>'.($k+1).'</td>
					<td>'.($v['sendtype']=='0'?"乐园卡":"田园卡").'</td>';
			if($v['sendtype']=='0'){
				$s .= '<td> </td>';
			}else{
				$s .= '<td>'.$v['deliver_val'].'</td>';
			}	
			$s .= '		
					<td>'.$v['classes'].'</td>
					<td>'.$v['username'].'</td>
					<td>'.$v['name'].'</td>
					<td>'.$v['sex'].'</td>
					<td>'.$v['birthday'].'</td>
					<td>'.$v['identname'].'</td>
					<td>'.$v['identnumber'].'</td>
					<td>'.$v['hometown'].'</td>
					<td>'.$v['foodlike'].'</td>
					<td>'.$v['phone'].'</td>
					<td>'.$v['addr'].'</td>
					<td>'.$v['tel'].'</td>
					<td>'.$v['email'].'</td>
					<td>'.$v['busiman'].'</td>
					<td>'.$v['source'].'</td>
					<td>'.$v['remark'].'</td>
					
					<td>'.$v['sendweek1'].'</td>
					<td>'.$v['sendweek2'].'</td>
					<td>'.$v['province'].'</td>
					<td>'.$v['city'].'</td>
					<td>'.$v['area'].'</td>
					<td>'.$v['zone'].'</td>
					<td>'.$v['sendaddr'].'</td>
					<td>'.$v['sendman'].'</td>
					<td>'.$v['sendphone'].'</td>
					<td>'.$v['sendtime'].'</td>
					<td>'.$v['sendremark'].'</td>
					
					<td>'.$v['bsendaddr'].'</td>
					<td>'.$v['bsendman'].'</td>
					<td>'.$v['bsendphone'].'</td>
					<td>'.$v['bsendtime'].'</td>
					
					<td>'.$v['contractcode'].'</td>
					<td>'.$v['contractmoney'].'</td>
					<td>'.$v['contractdate'].'</td>
					<td>'.$v['contractremark'].'</td>
				</tr>
			';
		} 
		$s .= '
			</tbody>
		</table>
		';
		return $s; 

	}
	
}

?>